<?php Yii::app()->clientScript->beginScript('custom-script'); ?>
<script type="text/javascript">
    function generateBarcode(code){
        var value = code;
        var btype = 'code128';
        var renderer = 'css';

        var settings = {
            output:renderer,
            bgColor: '#FFFFFF',
            color: '#000000',
            barWidth: 1,
            barHeight: 50
        };
        $("#img-barcode").html("").show().barcode(value, btype, settings);
    }
    $(document).ready(function() {
        generateBarcode('<?php echo $model->id_by_matter; ?>');
    });
</script>
<?php Yii::app()->clientScript->endScript();?>
<?php
$flashMessages = Yii::app()->user->getFlashes();
if ($flashMessages) {
    foreach($flashMessages as $key => $message) {
        echo '<div class="alert alert-' . $key . ' fade in"><button type="button" class="close" data-dismiss="alert">×</button>' . $message . "</div>\n";
    }
}
?>

<div id="yw0">
    <a class="btn-back pull-right" href="<?php echo $this->createUrl('task/index')?>">← <?php echo Yii::t('app', 'Back to task list') ?></a>
    <ul id="yw1" class="nav nav-tabs">
        <li class=""><a data-toggle="tab" href="#yw0_tab_1"><?php echo Yii::t('app', 'Detail task') ?></a></li>
        <li class="active"><a data-toggle="tab" href="#yw0_tab_2"><?php echo Yii::t('app', 'Steps analyst') ?></a></li>
        <li class=""><a data-toggle="tab" href="#yw0_tab_3"><?php echo Yii::t('app', 'Update status') ?></a></li>
    </ul>
    <div class="tab-content">
        <div id="yw0_tab_1" class="tab-pane fade">
            <fieldset>
                <legend>
                    <?php echo Yii::t('app', 'View task detail') ?>
                </legend>
                <?php
                $this->widget('bootstrap.widgets.TbDetailView', array(
                    'data'=>$data,
                    'attributes'=>array(
                        array('name'=>'client_company', 'label'=>Yii::t('app', 'Client company')),
                        array('name'=>'contact', 'label'=>Yii::t('app', 'Contact')),
//                        array('name'=>'trensporter_company', 'label'=>Yii::t('app', 'Transport company')),
                        array('name'=>'trensporter', 'label'=>Yii::t('app', 'Transporter')),
                        array('name'=>'attribute_matter', 'label'=>Yii::t('app', 'Matter name')),
//                array('name'=>'content_matter', 'label'=>Yii::t('app', 'Matter content')),
                        array('name'=>'status', 'label'=>Yii::t('app', 'Status')),
                        array('name'=>'deadline', 'label'=>Yii::t('app', 'Deadline')),
                        array('name'=>'delivery_date', 'label'=>Yii::t('app', 'Delivery date')),

                    ),
                ));
                ?>

            </fieldset>
        </div>

        <div id="yw0_tab_2" class="tab-pane fade active in">
            <fieldset>
                <legend>
                    <?php echo Yii::t('app', 'Step analyst') ?>
                </legend>
				<div class="pull-right">
					<div id="img-barcode"></div>
					&nbsp;&nbsp;&nbsp;&nbsp;
					<?php $image = CHtml::image(Yii::app()->getBaseUrl().'/images/print.png', ''); ?>
					<?php //echo CHtml::link($image, $this->createUrl('task/print', array('c'=>$model->id_by_matter)), array('id'=>'print-url', 'target'=> '_blank')) ?>
				</div>
		
                <?php $form=$this->beginWidget('CActiveForm', array(
                    'id'=>'task-analyst-form',
                    'action'=>Yii::app()->createUrl('task/analyststt'),
                    'enableAjaxValidation'=>false,
                    'htmlOptions'=>array('enctype' => 'multipart/form-data')
                ));
                ?>
                <div class="pull-right btn-toolbar inline">
                    <?php echo CHtml::dropDownList('status', '', Constant::getStatus(), array(
                        'empty'=>'',
                        'style' => 'margin-bottom:0px; margin-right:10px;width:130px;',
                    ))?>
                    <?php echo CHtml::hiddenField('id_task', $model->id_task)?>
                    <?php echo CHtml::hiddenField('id_analyster', $model->responsible)?>
                    <?php
                    $this->widget('bootstrap.widgets.TbButton', array(
                        'buttonType' => 'submit',
                        'type' => 'info',
                        'label' => Yii::t('app', 'Change status steps'),
                        'icon' => 'check white'
                    ));
                    ?>
                </div>
                <?php
                //    $this->widget('zii.widgets.grid.CGridView', array(
                $this->widget('bootstrap.widgets.TbGridView', array(
                    'id'=> 'task',
                    'dataProvider'=>$modelTaskAnalyst->search_task($model->id_task),
                    'enableSorting' => false,
                    'type' => 'striped',
                    'summaryText' => '',
                    'columns'=>array(
                        array(
                            'value'=>'$data->id_task_analyst',
                            'class'=>'CCheckBoxColumn',
                            'selectableRows' => 2,
                            'checkBoxHtmlOptions' => array(
                                'name' => 'ids[]',
                            ),
                        ),
                        'step_analyst',
                        array(
                            'name' => 'date_add',
                            'value'=> 'date("Y-m-d", strtotime($data->date_add))',
                        ),
                        array(
                            'name' => 'date_upd',
                            'value'=> 'date("Y-m-d", strtotime($data->date_upd))',
                        ),
                        array(
                            'name' => 'status',
                            'value'=> 'Common::getValue($data->status, Constant::getStatus())',
                            'cssClassExpression'=>'"hnx-".Constant::getStatustag($data->status)',
                        ),
                        array(
                            'class'=>'bootstrap.widgets.TbButtonColumn',
                            'template'=>'{views_option}',
                            'buttons'=>array
                            (
                                'views_option' => array
                                (
                                    'label'=>Yii::t("app", "Views special analyst"),
                                    'visible' => '($data->special_analyst)?true:false;',
                                    'icon'=>'pencil',
//                                    'url'=>'Yii::app()->createUrl("special/analyst", array("id"=>$data->id_task_analyst))',
                                    'url'=>'',
                                    'options'=>array(
//                                        'class'=>'btn btn-small btn-success',
                                        'data-toggle'=>'modal',
                                        'data-target' =>'#modal_special',
                                        'class' => 'pointer'
                                    ),
                                ),
                            ),
                            'htmlOptions'=>array(
                                'style'=>'width: 220px',
                            ),
                        ),
                        'note',
                    ),
                ));
                ?>
                <?php $this->endWidget(); ?>
            </fieldset>

            <?php if(!is_null($modelTaskAnalystSpecial)): ?>
                <?php //Common::debug($modelTaskAnalystSpecial->id_task_analyst) ?>
                <!-- Modal test-->
                <div class="modal fade" id="modal_special" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
                    <div class="modal-dialog">
                        <div class="modal-content">
                            <?php $form = $this->beginWidget('bootstrap.widgets.TbActiveForm', array(
                                'id'=>'horizontalForm',
                                'type'=>'horizontal',
                            ));?>

                            <div class="modal-header">
                                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                                <h4 class="modal-title" id="myModalLabel"><?php echo Yii::t('app', 'Special value') ?></h4>
                            </div>
                            <div class="modal-body">
                                <?php
                                $flashMessages = Yii::app()->user->getFlashes();
                                if ($flashMessages) {
                                    foreach($flashMessages as $key => $message) {
                                        echo '<div class="alert alert-' . $key . ' fade in"><button type="button" class="close" data-dismiss="alert">×</button>' . $message . "</div>\n";
                                    }
                                }
                                ?>

                                <?php echo $form->textFieldRow($modelTaskAnalystSpecial, 'quantity'); ?>
                                <?php echo $form->textFieldRow($modelTaskAnalystSpecial, 'subject'); ?>
                                <?php echo $form->textFieldRow($modelTaskAnalystSpecial, 'weight_ct'); ?>
                                <?php echo $form->textFieldRow($modelTaskAnalystSpecial, 'length_diameter_1'); ?>
                                <?php echo $form->textFieldRow($modelTaskAnalystSpecial, 'width_diameter_1'); ?>
                                <?php echo $form->textFieldRow($modelTaskAnalystSpecial, 'thickness'); ?>
                                <?php echo $form->textFieldRow($modelTaskAnalystSpecial, 'size'); ?>
                                <?php echo $form->textFieldRow($modelTaskAnalystSpecial, 'comment'); ?>
                                <?php echo $form->textFieldRow($modelTaskAnalystSpecial, 'other_1'); ?>
                                <?php echo $form->textFieldRow($modelTaskAnalystSpecial, 'orther_2'); ?>
                                <?php echo $form->textFieldRow($modelTaskAnalystSpecial, 'final_certif'); ?>
                                <?php echo $form->textFieldRow($modelTaskAnalystSpecial, 'invoice_certif'); ?>
                                <?php echo $form->textFieldRow($modelTaskAnalystSpecial, 'cleaning_bill'); ?>
                                <?php echo $form->textFieldRow($modelTaskAnalystSpecial, 'gtl_ref'); ?>
                                <?php echo $form->textFieldRow($modelTaskAnalystSpecial, 'weight'); ?>
                                <?php echo $form->textFieldRow($modelTaskAnalystSpecial, 'size_2'); ?>
                                <?php echo $form->textFieldRow($modelTaskAnalystSpecial, 'dimensions'); ?>
                                <?php echo $form->textFieldRow($modelTaskAnalystSpecial, 'packing'); ?>
                            </div>
                            <div class="modal-footer">
                                <button type="button" class="btn btn-default" data-dismiss="modal"><?php echo Yii::t('app', 'Close') ?></button>
<!--                                <button type="submit" class="btn btn-primary">--><?php //echo Yii::t('app', 'Save changes') ?><!--</button>-->
                                <?php
                                $this->widget('bootstrap.widgets.TbButton', array(
                                    'buttonType' => 'submit',
                                    'type' => 'primary',
                                    'label' => Yii::t('app', 'Save'),
                                    'icon' => 'plus-sign white'
                                ));
                                ?>
                            </div>
                            <?php $this->endWidget();?>

                        </div><!-- /.modal-content -->
                    </div><!-- /.modal-dialog -->
                </div><!-- /.modal -->
            <?php endif ?>

        </div>

        <div id="yw0_tab_3" class="tab-pane fade">
            <?php $form = $this->beginWidget('bootstrap.widgets.TbActiveForm', array(
                'id'=>'horizontalForm',
                'type'=>'horizontal',
            ));?>

            <fieldset>
                <legend>
                    <?php echo Yii::t('app', 'Update status') ?>
                </legend>
                <?php if($model->note): ?>
                    <div class="control-group ">
                        <label class="control-label">
                            <?php echo Yii::t('app', 'Comment form analyster') ?>
                        </label>
                        <div class="controls">
                            <?php echo nl2br($model->note); ?>
                        </div>
                    </div>
                <?php endif ?>
                <?php echo $form->dropDownListRow($model, 'statusby', Constant::getUpdateStatusBy(), array(
                    'empty'=>''
                )); ?>
                <?php echo $form->dropDownListRow($model, 'status', Constant::getStatus()); ?>

                <div class="" style="display: none;" id="action_close_status">
                    <?php echo $form->checkBoxRow($model, 'close_sms_to_contact', array())?>
                    <div id="close_sms_to_contact" style="display: none;">
                        <?php echo $form->textAreaRow($model, 'close_sms_content', array('rows' => 8, 'class' => 'span5')); ?>
                    </div>

                    <?php echo $form->checkBoxRow($model, 'close_email_to_contact', array())?>
                    <div id="close_email_to_contact" style="display: none;">
                        <?php echo $form->textAreaRow($model, 'close_email_content', array('rows' => 8, 'class' => 'span5')); ?>
                    </div>
                </div>
            </fieldset>
            <div class="form-actions">
                <?php
                $this->widget('bootstrap.widgets.TbButton', array(
                    'buttonType' => 'submit',
                    'type' => 'primary',
                    'label' => Yii::t('app', 'Submit'),
                    'icon' => 'plus-sign white'
                ));
                ?>
            </div>
            <?php $this->endWidget();?>
        </div>
    </div>
    <script type="text/javascript">
        $( document ).ready(function() {
            $('#Task_status').change(function(){
                var status = this.val();
                console.log('status');
                var close = '<?php echo Constant::STATUS_CLOSE; ?>';
                if(status==close){
                    console.log('true');
                    $('#action_close_status').slideDown();
                }else{
                    console.log('false');
                    $('#action_close_status').slideUp();
                }
            });
        });
    </script>

    <?php if(isset($_POST['TaskAnalystSpecial'])): ?>
    <script type="text/javascript">
        $( document ).ready(function() {
            $('#modal_special').modal('show');
        });
    </script>
    <?php endif ?>
</div>


